package com.bilgeadam.hibernate.program;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 *  
 * @author Bora SAYINER
 * @since Nov 15, 2014 3:57:55 PM
 * @version 1.0.0
 */
public class Driver {

	public static void main(String[] args) {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		{
			Employee employee = new Employee();
			employee.setFirstName("Haluk");
			employee.setLastName("GWT");
			{
				Vehicle mazda = new Vehicle();
				mazda.setBrand("Mazda");
				mazda.setModel("Mazda 3");
				employee.setVehicle(mazda);
				
			}
			session.save(employee);
//			
//			Employee employee = (Employee) session.get(Employee.class, 3L);
//			System.out.println(employee);
//			System.out.println(employee.getVehicle());
//			
//			Vehicle vehicle = (Vehicle) session.get(Vehicle.class, 1L);
//			Employee employee = vehicle.getEmployee();
//			System.out.println(employee);
		}
		transaction.commit();
		session.close();
		sessionFactory.close();
	}
}
